<style>
  .form-signin {
    max-width: 500px;
    padding: 15px;
    margin: 0 auto;
  }
  .form-signin .form-signin-heading,
  .form-signin .checkbox {
    margin-bottom: 10px;
  }
  .form-signin .checkbox {
    font-weight: normal;
  }
  .form-signin .form-control {
    position: relative;
    height: auto;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    padding: 10px;
    margin: 5px 0px 5px 0px;
    font-size: 16px;
  }
  .form-signin .form-control:focus {
    z-index: 2;
  }
  .form-signin input {
    margin-bottom: -1px;
    border-bottom-right-radius: 0;
    border-bottom-left-radius: 0;
  }
  .form-signin input[type="password"] {
    margin-bottom: 10px;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }
</style>

<template>
  <div class="container" style="background: #4C637B;">
    <validator name='v'>
      <form class="form-signin" novalidate @submit.prevent="signIn()">
        <div>
          <!-- <img src="../../assets/logo1.png" class="center-block img-responsive"></img> -->
        </div>
        <h2 class="form-signin-heading text-center" style="color: #fff;">手机抄表系统</h2>
        <h4 class="form-signin-heading text-center" style="color: #fff;">欢迎使用手机抄表系统</h4>
        <!-- <h5 class="form-signin-heading text-center" @click="backupDatabase">当前版本：0.{{version}}</h5> -->
        <input id="ename" style="margin-top: 100px;" class="form-control" placeholder="请输入用户名" autofocus v-model="model.ename" v-validate:ename='{ required: true }'>
        <input type="password"  id="inputPassword" class="form-control" placeholder="请输入密码" v-model="model.password" v-validate:password='{ required: true }'>
        <button :disabled="!$v.valid" class="btn btn-lg btn-danger btn-block" type="submit" style="color: #fff; ">登录</button>
      </form>
    </validator>
    <div class="login-footer login-footer_fixed-bottom">
      <p class="login-footer__links">
        <a href="javascript:home();" class="login-footer__link"></a>
      </p>
      <p class="login-footer__text">Copyright @ v1.0.0 手机抄表</p>
    </div>
  </div>
</template>
<script>
  import AppData from '../../stores/AppData'
  import config from '../config'

  export default {
    title: '登录系统',
    data () {
      return {
        model: {
          ename: '',
          password: ''
        }
      }
    },
    methods: {
      backupDatabase () {
        HostApp.backupDatabase()
      },
      load () {
        if (this.model.ename === '' || this.model.password === '') {
          HostApp.alert('登录失败, 用户名或密码不能为空！')
          return
        }
        this.$resetpost(config.resultUrl + 'rs/logic/phonelogin', {data: this.model}, {resolveMsg: null, rejectMsg: '登录失败：'}).then((ret) => {
          console.log(ret.data)
          if (ret.data.state === 0) {
            this.$goto('home')
            AppData.loginUser = ret.data.data
          } else {
            HostApp.alert('登录失败 ' + ret.data.msg)
          }
        })
      },
      signIn () {
        this.login = true
        // 模拟手机，定时提取

        // 获取登录加载数据
        this.load()
      },
      isJSON (str) {
        if (typeof str == 'string') {
          try {
            var obj = JSON.parse(str)
            if (typeof obj == 'object' && obj ) {
              return true
            } else {
              return false
            }
          } catch (e) {
            console.log('error：'+str+'!!!'+e);
            return false
          }
        }
        console.log('It is not a string!')
      }
    }
  }
</script>
<style scoped>
  .login-footer_fixed-bottom {
    height: auto;
    position: fixed;
    bottom: .52em;
    left: 0;
    right: 0;
  }
  .login-footer {
    color: #999;
    font-size: 14px;
    text-align: center;
  }
  .login-footer__link {
    color: #586C94;
  }
</style>
